﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace NJL.WebUsers.Controls
{
    public partial class WUCIndexTrip : BaseUserControl
    {
        public string beforeID;
        public string beforePersonId;
        public string iding;
        public string personIding;
        public string afterId;
        public string afterIding;
        NJL.BLL.NJL_NEWS bll = new BLL.NJL_NEWS();

        protected string BEFORE_ID;
        protected string BEFORE_PERSON_ID;
        protected string BEFORE_IMAGE_URL;
        protected string TRIPING_ID;
        protected string TRIPING_PERSON_ID;
        protected string TRIPING_IMAGE_URL;
        protected string AFTER_ID;
        protected string AFTER_PERSON_ID;
        protected string AFTER_IMAGE_URL;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                #region 游前
                DataSet ds = bll.GetList(9, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND TYPE_CODE='1' and ID not in (select top 1 ID from NJL_NEWS where NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND TYPE_CODE='1' order by VISIT_COUNT desc,CREATE_DATE_TIME desc)", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
                rptBefore.DataSource = ds;
                rptBefore.DataBind();
                ds = bll.GetList(1, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND TYPE_CODE='1'", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    BEFORE_ID = ds.Tables[0].Rows[0][0].ToString();
                    BEFORE_PERSON_ID = ds.Tables[0].Rows[0]["NJL_PERSON_ID"].ToString();
                    if (ds.Tables[0].Rows[0]["IMAGE_CODE"].ToString() != "")
                    {
                        string imgurl = GetImageUrl(ds.Tables[0].Rows[0]["IMAGE_CODE"].ToString(),"2");
                        BEFORE_IMAGE_URL = imgurl;
                    }
                    else
                    {
                        BEFORE_IMAGE_URL = "~/Images/nopic.jpg";
                    }
                    string content = ds.Tables[0].Rows[0]["NEWS_SUBJECT_TITLE"].ToString();
                    if (content.Length > 52)
                    {
                        litBeforeContent.Text = content.Substring(0, 52) + "...";

                    }
                    else
                    {
                        litBeforeContent.Text = content;
              
                    }
                }
                #endregion
                #region 游中
                ds = bll.GetList(9, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND TYPE_CODE='2' and ID not in (select top 1 ID from NJL_NEWS where NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND TYPE_CODE='2' order by VISIT_COUNT desc,CREATE_DATE_TIME desc)", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
                rpting.DataSource = ds;
                rpting.DataBind();
                ds = bll.GetList(1, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND TYPE_CODE='2'", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    TRIPING_ID = ds.Tables[0].Rows[0][0].ToString();
                    TRIPING_PERSON_ID = ds.Tables[0].Rows[0]["NJL_PERSON_ID"].ToString();
                    if (ds.Tables[0].Rows[0]["IMAGE_CODE"].ToString() != "")
                    {
                        string imgurl = GetImageUrl(ds.Tables[0].Rows[0]["IMAGE_CODE"].ToString(),"2");
                        TRIPING_IMAGE_URL = imgurl;
                    }
                    else
                    {
                        TRIPING_IMAGE_URL = "~/Images/nopic.jpg";
                    }
                    string content = ds.Tables[0].Rows[0]["NEWS_SUBJECT_TITLE"].ToString();
                    if (content.Length > 52)
                    {
                        liting.Text = content.Substring(0, 52) + "...";
                    }
                    else
                    {
                        liting.Text = content;
                    }
                }
                #endregion
                #region 游后
                ds = bll.GetList(9, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND TYPE_CODE='3' and ID not in (select top 1 ID from NJL_NEWS where NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND TYPE_CODE='3' order by VISIT_COUNT desc,CREATE_DATE_TIME desc)", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
                rptAfter.DataSource = ds;
                rptAfter.DataBind();
                ds = bll.GetList(1, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND TYPE_CODE='3'", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    AFTER_ID = ds.Tables[0].Rows[0][0].ToString();
                    AFTER_PERSON_ID = ds.Tables[0].Rows[0]["NJL_PERSON_ID"].ToString();
                    if (ds.Tables[0].Rows[0]["IMAGE_CODE"].ToString() != "")
                    {
                        string imgurl = GetImageUrl(ds.Tables[0].Rows[0]["IMAGE_CODE"].ToString(),"2");
                        AFTER_IMAGE_URL = imgurl;
                    }
                    else
                    {
                        AFTER_IMAGE_URL = "~/Images/nopic.jpg";
                    }
                    string content = ds.Tables[0].Rows[0]["NEWS_SUBJECT_TITLE"].ToString();
                    if (content.Length > 52)
                    {
                        litAfter.Text = content.Substring(0, 52) + "...";
                    }
                    else
                    {
                        litAfter.Text = content;
                    }
                }
                #endregion
            }
        }
        protected Model.NJL_USER GetUserByID(string UserID)
        {
            return new BLL.NJL_USER().GetModel(UserID);
        }

    }
}